﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BGCOP.CAVTOP.BUSINESSLAYER
{
    public class VehiculosParqueos
    {
        public List<viParqueoVehiculo> listarTodos()
        {
            masterDBACEntities db = new masterDBACEntities();
            var modv = from d in db.viParqueoVehiculo orderby d.Parqueadero select d;
            return modv.ToList();
        }
        public void Agregar(int idParqueo, int idVehiculo, DateTime fechaC, int usuarioAct, int diaS=1, 
                            string obs = "Sin Obeservaciones",
                            bool d0 = false, bool d1 = false, bool d2 = false, bool d3 = false, bool d4 = false,
                            bool d5 = false, bool d6 = false)
        {
            TvehiculoParqueo obj = new TvehiculoParqueo();
            obj.idParqueadero = idParqueo;
            obj.idVehiculo = idVehiculo;
            obj.diaSemana = (byte)diaS;
            obj.ObservacionesVP = obs;
            obj.dia1 = d0;
            obj.dia2 = d1;
            obj.dia3 = d2;
            obj.dia4 = d3;
            obj.dia5 = d4;
            obj.dia6 = d5;
            obj.dia7 = d6;
            obj.fechaUltimaGestion = fechaC;
            obj.usuarioUltimaGestion = usuarioAct;
            masterDBACEntities db = new masterDBACEntities();
            db.AddToTvehiculoParqueo(obj);
            db.SaveChanges();
        }
        public void Eliminar(int idParqueo, int idVehiculo)
        {
            masterDBACEntities db = new masterDBACEntities();
            TvehiculoParqueo obj = db.TvehiculoParqueo.FirstOrDefault(c => c.idVehiculo == idVehiculo && c.idParqueadero == idParqueo);
            if (obj != null)
            {
                db.TvehiculoParqueo.DeleteObject(obj);
            }
        }
        public TvehiculoParqueo consultarreg(int idParqueo, int idVehiculo)
        {
            masterDBACEntities db = new masterDBACEntities();
            var res =
                (from a in db.TvehiculoParqueo where a.idParqueadero == idParqueo && a.idVehiculo == idVehiculo select a)
                    .FirstOrDefault();
            return res;
        }
        public void modificar(int idParqueo, int idVehiculo,int dia,bool d0 = false)
        {
            masterDBACEntities db = new masterDBACEntities();
            TvehiculoParqueo  obj = db.TvehiculoParqueo.FirstOrDefault(c => c.idVehiculo  == idVehiculo && c.idParqueadero == idParqueo);
            if (obj != null)
            {
                switch (dia)
                {
                    case 0:
                        obj.dia1 = d0;
                        break;
                    case 1:
                        obj.dia2 = d0;
                        break;
                    case 2:
                        obj.dia3 = d0;
                        break;
                    case 3:
                        obj.dia4 = d0;
                        break;
                    case 4:
                        obj.dia5 = d0;
                        break;
                    case 5:
                        obj.dia6 = d0;
                        break;
                    case 6:
                        obj.dia7 = d0;
                        break;

                }
                db.SaveChanges();
            }
        }
        public void Modificar(int idParqueo, int idVehiculo,DateTime fechaC, int usuarioAct, int diaS=-1, 
                            string obs = "Sin Obeservaciones",
                            bool d0 = false, bool d1 = false, bool d2 = false, bool d3 = false, bool d4 = false,
                            bool d5 = false, bool d6 = false)
        {
            masterDBACEntities db = new masterDBACEntities();
            TvehiculoParqueo  obj = db.TvehiculoParqueo.FirstOrDefault(c => c.idVehiculo  == idVehiculo && c.idParqueadero == idParqueo);
            if (obj != null)
            {
                obj.ObservacionesVP = obs;

                switch (diaS)
                {
                    case 0:
                        obj.dia1 = d0;
                        break;
                    case 1:
                        obj.dia2 = d1;
                        break;
                    case 2:
                        obj.dia3 = d2;
                        break;
                    case 3:
                        obj.dia4 = d3;
                        break;
                    case 4:
                        obj.dia5 = d4;
                        break;
                    case 5:
                        obj.dia6 = d5;
                        break;
                    case 6:
                        obj.dia7 = d6;
                        break;
                    case -1:
                        obj.dia1 = d0;
                        obj.dia2 = d1;
                        obj.dia3 = d2;
                        obj.dia4 = d3;
                        obj.dia5 = d4;
                        obj.dia6 = d5;
                        obj.dia7 = d6;
                        break;
                }
                
                obj.fechaUltimaGestion = fechaC;
                obj.usuarioUltimaGestion = usuarioAct;
                db.SaveChanges();
            }
        }
    }
}
